package com.classbook.violet.baigiang6.object;

import java.util.ArrayList;
import java.util.List;

import com.classbook.violet.baigiang6.subject.LessonNode;

import android.app.Application;

public class GlobalVar {
	
	private static GlobalVar instance;
	
	private List<LessonNode> listDown = new ArrayList<LessonNode>();
	
	public GlobalVar(){}
	
	 public static synchronized GlobalVar getInstance(){
	    if(instance == null){
	       instance = new GlobalVar();
	    }
	     return instance;
	 }
	 
	 public List<LessonNode> getList(){
		 return listDown;
	 }
	 
	 public void add (LessonNode file){
		 this.listDown.add(file);
	 }
	 
	 public void remove (LessonNode lesson){
		 for (int i = 0; i < this.listDown.size(); i++){
			 if (lesson.label.contains(this.listDown.get(i).label)){
				 this.listDown.remove(i);
			 }
		 }
	 }
	 
	 public void setSize (LessonNode lesson){
		 for (int i = 0; i < this.listDown.size(); i++){
			 if (lesson.label.contains(this.listDown.get(i).label)){
				 this.listDown.get(i).totalSize = lesson.totalSize;
				 this.listDown.get(i).downSize = lesson.downSize;
			 }
		 }
	 }
	 
	 public LessonNode getLesson (LessonNode lesson){
		 LessonNode lesson_temp = null;
		 for (int i = 0; i < this.listDown.size(); i++){
			 if (lesson.label.contains(this.listDown.get(i).label)){
				 lesson_temp = this.listDown.get(i);
			 }
		 }
		 return lesson_temp;
	 }
	 
	 public void setList (List<LessonNode> listDown){
		 this.listDown = listDown;
	 }
	 
	 public Boolean checkLesson (LessonNode lesson){
		 Boolean check = false;
		 for (int i = 0; i < this.listDown.size(); i++){
			 if (lesson.label.contains(this.listDown.get(i).label)){
				 check = true;
			 }
		 }
		 return check;
	 }

}
